package com.thf.controller.user;

import com.alibaba.fastjson.JSON;
import com.thf.model.ResultData;
import com.thf.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Map;


@Controller
public class UserAddController{

    @Resource
    private UserService userService ;

    @RequestMapping("/user/add")
    @ResponseBody
    protected String userAdd(String val) throws ServletException, IOException {
        //     0。乱码处理
//        req.setCharacterEncoding("UTF-8");
//        resp.setCharacterEncoding("UTF-8");
//        //        1.得到前端传递过来的数据
//        String val = req.getParameter("val");
        Map map = JSON.parseObject(val, Map.class);
        //        -返回值
        ResultData result = userService.add(map);
//       反馈给前端--返回值
        String resJson = JSON.toJSONString(result);
//        resp.getWriter().println(resJson);
        return resJson ;
    }
}
